Allow string to be modified during parse. Ugh.
authorRobert Lipe <robertlipe@gpsbabel.org>
Tue, 9 Oct 2018 03:27:05 +0000 (03:27 +0000)
committerRobert Lipe <robertlipe@gpsbabel.org>
Tue, 9 Oct 2018 03:27:05 +0000 (03:27 +0000)
csv_util.cc

index 67854121a36bcc109b5ef827342f0c4530dce790..ba1685ed2b5740faec06f21a88c50f7a35f28db8 100644 (file)
@@ -1441,8 +1441,9 @@ xcsv_data_read(void)
     }
     if (!buff.isEmpty()) {
       Waypoint* wpt_tmp = new Waypoint;
-
-      const char* s = strdup(CSTR(buff));
+      // tbuf is a temporary copy of buff since we modify it. :-(
+      char *tbuf = xstrdup(buff);
+      const char* s = tbuf;
       s = csv_lineparse(s, CSTR(xcsv_file.field_delimiter),
                         CSTR(xcsv_file.field_encloser), linecount);
 
@@ -1518,6 +1519,7 @@ xcsv_data_read(void)
       default:
         ;
       }
+      xfree(tbuf);
     }
   }
 }